nanopyx.liquid.__interpolation_tools__
1import numpy as np 2 3 4def check_image(image: np.ndarray) -> np.ndarray: 5 image = np.asarray(image) 6 if type(image) is not np.ndarray: 7 raise TypeError("Image must be of type np.ndarray") 8 if image.ndim != 2 and image.ndim != 3: 9 raise ValueError("Image must be 2D and 3D (sequence of 2D images)") 10 if image.dtype != np.float32: 11 image = image.astype(np.float32, copy=False) 12 if image.ndim == 2: 13 image = image.reshape((1, image.shape[0], image.shape[1])) 14 return image 15 16 17def value2array(v, n_frames: int) -> np.ndarray: 18 """ 19 Convert a value to an array of the same length as the number of frames 20 :param v: value to convert 21 :type v: int, float, np.ndarray 22 :param n_frames: number of frames 23 :return: array of the same length as the number of frames 24 """ 25 if type(v) in (int, float): 26 v = np.ones(n_frames, dtype=np.float32) * v 27 return v
def
check_image(image: numpy.ndarray) -> numpy.ndarray:
5def check_image(image: np.ndarray) -> np.ndarray: 6 image = np.asarray(image) 7 if type(image) is not np.ndarray: 8 raise TypeError("Image must be of type np.ndarray") 9 if image.ndim != 2 and image.ndim != 3: 10 raise ValueError("Image must be 2D and 3D (sequence of 2D images)") 11 if image.dtype != np.float32: 12 image = image.astype(np.float32, copy=False) 13 if image.ndim == 2: 14 image = image.reshape((1, image.shape[0], image.shape[1])) 15 return image
def
value2array(v, n_frames: int) -> numpy.ndarray:
18def value2array(v, n_frames: int) -> np.ndarray: 19 """ 20 Convert a value to an array of the same length as the number of frames 21 :param v: value to convert 22 :type v: int, float, np.ndarray 23 :param n_frames: number of frames 24 :return: array of the same length as the number of frames 25 """ 26 if type(v) in (int, float): 27 v = np.ones(n_frames, dtype=np.float32) * v 28 return v
Convert a value to an array of the same length as the number of frames
Parameters
- v: value to convert
- n_frames: number of frames
Returns
array of the same length as the number of frames